<template>
  <el-form :model="ruleForm" ref="ruleForm" class="demo-ruleForm">
    <el-form-item label="岗位类目" prop="classify">
      <el-cascader
        :options="options"
        :props="CascaderProps"
        v-model="ruleForm.classify"
      ></el-cascader>
    </el-form-item>
    <el-form-item label="mock数据" prop="region">
      <el-select v-model="ruleForm.jobdata" placeholder="请选择mock数据名">
        <el-option label="前端数据" value="H5"></el-option>
        <el-option label="大数据" value="data"></el-option>
        <el-option label="设计" value="design"></el-option>
        <el-option label="行政" value="executive"></el-option>
        <el-option label="Java" value="java"></el-option>
        <el-option label="运维" value="om"></el-option>
        <el-option label="运营" value="operation"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')"
        >批量录入数据【点击前请先修改ID、Key】</el-button
      >
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import { classifyGet, companyBatch } from "@/api/job";
import mock from "./mock/index";
export default {
  data() {
    return {
      ruleForm: {
        classify: [],
        jobdata: "",
      },
      options: [],
      CascaderProps: {
        //自定义级联菜单数据包字段
        label: "name",
        value: "name",
        children: "list",
      },
    };
  },
  created() {
    classifyGet(true).then((res) => {
      // this.tableData = res.data.results;
      let { results } = res.data;
      let parentArr = results.filter((item) => item.parent == "0-0");
      parentArr.forEach((item) => {
        item.list = results.filter((child) => child.parent == item.objectId);
      });
      console.log(parentArr);
      this.options = [...parentArr];
    });
  },
  methods: {
    submitForm() {
      console.log(this.ruleForm);
      let list = mock[this.ruleForm.jobdata].zpData.jobList; //用select选择的数据包名，获取对应的数据包文件提供的数据
      // let list = mock.H5.zpData.jobList
      // let list = mock.java.zpData.jobList
      // let list = mock.design.zpData.jobList
      console.log(list);
      companyBatch(this.ruleForm.classify, list);
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
